/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_RTICONNEXT_ENTITY_MAPPING_MANAGER_HPP_
#define _DAL_RTICONNEXT_ENTITY_MAPPING_MANAGER_HPP_

#include <mutex>
#include <unordered_map>
#include "dal/topic.h"
#include "dal/publisher.h"
#include "dal/subscriber.h"
#include "dal/domain_participant.h"
#include "ndds/ndds_c.h"

static std::unordered_map<DDS_DataReader*, dal_datareader_t*> datareaderMap;
static std::unordered_map<DDS_DataWriter*, dal_datawriter_t*> datawriterMap;
static std::unordered_map<DDS_Publisher*, dal_publisher_t*> publisherMap;
static std::unordered_map<DDS_Subscriber*, dal_subscriber_t*> subscriberMap;
static std::unordered_map<DDS_Topic*, dal_topic_t*> topicMap;
static std::unordered_map<DDS_DomainParticipant*, dal_domain_participant_t*> domainParticipantMap;

static std::mutex datareaderMtx;
static std::mutex datawriterMtx;
static std::mutex publisherMtx;
static std::mutex subscriberMtx;
static std::mutex topicMtx;
static std::mutex domainParticipantMtx;

void EntityMappingAddDataReader(DDS_DataReader* key, dal_datareader_t* value);
void EntityMappingRemoveDataReader(DDS_DataReader* key);
void EntityMappingUpdateDataReader(DDS_DataReader* key, dal_datareader_t* value);
dal_datareader_t* EntityMappingGetDataReader(DDS_DataReader* key);

void EntityMappingAddDataWriter(DDS_DataWriter* key, dal_datawriter_t* value);
void EntityMappingRemoveDataWriter(DDS_DataWriter* key);
void EntityMappingUpdateDataWriter(DDS_DataWriter* key, dal_datawriter_t* value);
dal_datawriter_t* EntityMappingGetDataWriter(DDS_DataWriter* key);

void EntityMappingAddPublisher(DDS_Publisher* key, dal_publisher_t* value);
void EntityMappingRemovePublisher(DDS_Publisher* key);
void EntityMappingUpdatePublisher(DDS_Publisher* key, dal_publisher_t* value);
dal_publisher_t* EntityMappingGetPublisher(DDS_Publisher* key);

void EntityMappingAddSubscriber(DDS_Subscriber* key, dal_subscriber_t* value);
void EntityMappingRemoveSubscriber(DDS_Subscriber* key);
void EntityMappingUpdateSubscriber(DDS_Subscriber* key, dal_subscriber_t* value);
dal_subscriber_t* EntityMappingGetSubscriber(DDS_Subscriber* key);

void EntityMappingAddTopic(DDS_Topic* key, dal_topic_t* value);
void EntityMappingRemoveTopic(DDS_Topic* key);
void EntityMappingUpdateTopic(DDS_Topic* key, dal_topic_t* value);
dal_topic_t* EntityMappingGetTopic(DDS_Topic* key);

void EntityMappingAddDomainParticipant(DDS_DomainParticipant* key, dal_domain_participant_t* value);
void EntityMappingRemoveDomainParticipant(DDS_DomainParticipant* key);
void EntityMappingUpdateDomainParticipant(DDS_DomainParticipant* key, dal_domain_participant_t* value);
dal_domain_participant_t* EntityMappingUpdateGetDomainParticipant(DDS_DomainParticipant* key);

#endif  // _DAL_RTICONNEXT_ENTITY_MAPPING_MANAGER_HPP_